package com.suray.system.run.random.code.util;

import com.suray.basic.wcs.path.core.Node;

public class NavNode extends Node {

    /**
     * 顺序：从小到大
     */
    private int ladder;

    private boolean runEnd;

    private NodePoint nodePoint;

    private NavNode preNode;

    public NavNode(Node sourceNode) {
        super(sourceNode);
        setNodeType(sourceNode.getNodeType());
        setUp(sourceNode.getUp());
        setDown(sourceNode.getDown());
        setLeft(sourceNode.getLeft());
        setRight(sourceNode.getRight());

        runEnd = false;
    }

    public NavNode getPreNode() {
        return preNode;
    }

    public void setPreNode(NavNode preNode) {
        this.preNode = preNode;
    }

    public int getLadder() {
        return ladder;
    }

    public void setLadder(int ladder) {
        this.ladder = ladder;
    }

    public boolean isRunEnd() {
        return runEnd;
    }

    public void setRunEnd(boolean runEnd) {
        this.runEnd = runEnd;
    }

    public NodePoint getNodePoint() {
        return nodePoint;
    }

    public void setNodePoint(NodePoint nodePoint) {
        this.nodePoint = nodePoint;
    }

    /**
     * 当前点能否到达lastNode 且距离为1
     * @param lastNode
     * @return
     */
    public boolean near(NavNode lastNode) {
        if (getZ() != lastNode.getZ()) {
            return false;
        }

        if (getX() == lastNode.getX()) {
            if (getY() > lastNode.getY()) {
                if (getLeft() && (getY() - lastNode.getY()) == 1) {
                    return true;
                }
            } else if (getY() < lastNode.getY()) {
                if (getRight() && (lastNode.getY() - getY()) == 1) {
                    return true;
                }
            } else {
                return false;
            }
        } else if (getY() == lastNode.getY()) {
            if (getX() > lastNode.getX()) {
                if (getUp() && (getX() - lastNode.getX()) == 1) {
                    return true;
                }
            } else if (getX() < lastNode.getX()) {
                if (getDown() && (lastNode.getX() - getX()) == 1) {
                    return true;
                }
            } else {
                return false;
            }
        }

        return false;
    }

//    @Override
//    public String toString() {
//        return super.toString() + "--" + ladder;
//    }
}
